package com.cn.demo4;

import java.lang.reflect.Method;

public class Example4 {
    private void privateMethod(String message) {
        System.out.println("Private Message: " + message);
    }

    public static void main(String[] args) throws Exception {
        Class<Example4> clazz = Example4.class;

        // 获取私有方法对象
        Method method = clazz.getDeclaredMethod("privateMethod", String.class);

        // 设置方法可访问
        method.setAccessible(true);

        // 调用方法
        Example4 example = new Example4();
        method.invoke(example, "Hello, Private Reflection!");
    }
}
